package Java.BlackHorse.IO.zipStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class IODemo2 {
    public static void main(String[] args) throws IOException {
        File src = new File("IO\\zipStream\\a.txt");
        File dest = new File("IO\\zipStream");
        toZip(src,dest);
    }
    public static void toZip(File src, File dest) throws IOException {
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(dest,"a.zip")));
        ZipEntry entry = new ZipEntry(src.getName());
        zos.putNextEntry(entry);
        FileInputStream fis = new FileInputStream(src);
        int ch;
        while((ch = fis.read()) != -1){
            zos.write(ch);
        }
        fis.close();
        zos.closeEntry();
        zos.close();
    }
}
